﻿using Network.FrameSync.Server;
using Network.IPCWork;
using Network.Server;

namespace Server
{
    public class GameServer : ServerModule
    {
        private FSPManager _fsp;
        private IPCManager _ipc;

        public GameServer(int id, int port) : base()
        {
            this.id = id;
            this.port = port;
        }

        public override void Start()
        {
            _fsp = new FSPManager();
            _fsp.Init(port);

            _ipc = new IPCManager();
            _ipc.Init(id, port + 1);

            // 业务逻辑初始化
            XJGameManager.Instance.Init(_fsp);

            base.Start();
        }

        public override void Stop()
        {
            if (_fsp != null)
            {
                _fsp.Clean();
                _fsp = null;
            }
            if (_ipc != null)
            {
                _ipc.Clean();
                _ipc = null;
            }
        }

        public override void Tick()
        {
            _fsp.Tick();
            _ipc.Tick();
        }
    }
}